package com.xiangmu.controler;


import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.xiangmu.mappers.JiaruMapper;
import com.xiangmu.pojo.Jiaru;
import com.xiangmu.pojo.User;
import com.xiangmu.util.JsonResult;

@RestController
public class JiaruControler extends BaseController
{

	@Autowired
	private JiaruMapper jiaruMapper;
	
	@RequestMapping("/jiaruAdd")
	public JsonResult<Void> jiaruAdd(@RequestBody Jiaru jiaru) 
	{
		jiaruMapper.insert(jiaru);
        return new JsonResult<>(66);
		
    }
	
	
	@RequestMapping("/jiaruMine")
	public JsonResult<List> jiaruMine(HttpSession session) 
	{
		User user=(User)session.getAttribute("user");
		
		List<Jiaru> jiaruList=jiaruMapper.findByUser(user.getUid());
		
		return new JsonResult<>(66,jiaruList);
		
    }
	
	@RequestMapping("/jiaruDel")
	public JsonResult<Void> jiaruDel(int id) 
	{
		jiaruMapper.delete(id);
		return new JsonResult<>(66);
    }
	
	
	@RequestMapping("/jiaruMana")
	public JsonResult<List> jiaruMana() 
	{
		List<Jiaru> jiaruList=jiaruMapper.select("","");
		return new JsonResult<>(66,jiaruList);
		
    }
	
	
	
	@RequestMapping("/jiaruHuifu")
	public JsonResult<Void> jiaruHuifu(@RequestBody Jiaru jiaru) 
	{
		jiaruMapper.update(jiaru);
		return new JsonResult<>(66);
    }
	
	
	@RequestMapping("/jiaruRes")
	public JsonResult<List> jiaruRes(String xingming,String dianhua) 
	{
		List<Jiaru> jiaruList=jiaruMapper.select(xingming.trim(),dianhua.trim());
		
		return new JsonResult<>(66,jiaruList);
		
    }
	
	
}
